package com.dnake.facedemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import com.dnake.v792.OnSysMsgListener
import com.dnake.v792.api.SysLayer
import com.dnake.v792.phone.Call

class MainActivity : AppCompatActivity(), OnSysMsgListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        SysLayer.startService(this)
        SysLayer.setOnSysMsgListener(this)

        findViewById<Button>(R.id.register).setOnClickListener {
            val intent = Intent(this,FaceActivity::class.java)
            intent.putExtra("mode",2)
            startActivity(intent)
        }
        findViewById<Button>(R.id.face).setOnClickListener{
            val intent = Intent(this,FaceActivity::class.java)
            intent.putExtra("mode",1)
            startActivity(intent)
        }

        findViewById<Button>(R.id.delete_one).setOnClickListener{
           SysLayer.deleteFace(10100001)
        }

        findViewById<Button>(R.id.delete_all).setOnClickListener{
            SysLayer.clearFace()
        }

        findViewById<Button>(R.id.open_camera).setOnClickListener{
            SysLayer.snapshot()
        }

    }

    override fun key_mcu(p0: Int, p1: Int) {
    }

    override fun eio_mcu(p0: Int, p1: Int) {
    }

    override fun io_security(p0: Int) {
    }

    override fun call_incoming_received(p0: Call?, p1: String?) {
    }

    override fun call_outgoing_process(p0: Call?) {
    }

    override fun call_outgoing_ringing(p0: Call?) {
    }

    override fun call_stream_running(p0: Call?) {
    }

    override fun call_end(p0: Call?) {
    }

    override fun call_reset() {
    }

    override fun registration_success() {
    }

    override fun registration_failed() {
    }

    override fun v170_card(p0: String?, p1: Int) {
    }

    override fun msg_ctl(p0: String?, p1: Int) {
    }

    override fun touch() {
    }


    override fun onFaceDetect() {

    }

    override fun onFaceLived(mode: Int, url: String?) {
    }

    override fun onFaceIdent(d: Int, id: Int, uid: Int, black: Int) {
        runOnUiThread{
            Toast.makeText(this,"识别 $id",Toast.LENGTH_SHORT).show()
//            FaceActivity.instance.finish()
        }

    }

//    override fun onCardResult(card: String?, auth: Int) {
//
//    }

    override fun onFaceRegister() {
        runOnUiThread{
            Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show()
            FaceActivity.instance.finish()
        }

    }

    override fun onFaceCapture(url: String?) {
        runOnUiThread{
            Log.e("qpt","capture")
            Toast.makeText(this,"url = $url",Toast.LENGTH_SHORT).show()
        }
    }

    override fun onFaceReboot() {
    }


}